package com.cus.shd.sharingjdbc.switchDataSource.aop;

import com.cus.shd.sharingjdbc.switchDataSource.DataSourceContextHolder;
import com.cus.shd.sharingjdbc.switchDataSource.DataSourceEnum;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.util.WebUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ASUS
 * @Description TODO
 * @Date 2021/11/7 18:17
 **/

@Aspect
@Component
public class DataSourceAspect {


    @Around("@annotation(dataSourceTag)")
    public Object around(ProceedingJoinPoint proceedingJoinPoint, DataSourceTag dataSourceTag) throws Throwable {
        DataSourceEnum dataSourceEnum = dataSourceTag.value();
        DataSourceContextHolder.setDataSource(dataSourceEnum.toString());
        Object obj = proceedingJoinPoint.proceed();
        DataSourceContextHolder.clear();
        return obj;
    }
}
